//
//  ORShortcutsParser.m
//  OR_1
//
//  Created by Luboš Kulič on 8/4/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "ORShortcutsParser.h"


@implementation ORShortcutsParser

+(NSDictionary *) getORShortcutsTranslator {
	
	NSString *path = [[NSBundle bundleForClass:self] pathForResource:@"zkr_103" ofType:@"txt"];
	
	
	
	//[[NSBundle mainBundle] ]
	NSURL * file = [NSURL URLWithString:path];
	

	NSString * shortcuts =  [NSString stringWithContentsOfFile:path];//[NSString stringWithContentsOfURL:file];
	
	
	NSScanner * scanner = [NSScanner scannerWithString:shortcuts ];
	
	[scanner setCharactersToBeSkipped:[NSCharacterSet  whitespaceCharacterSet] ];
	
	NSString * line;
	
	NSCharacterSet * newline_set = [NSCharacterSet newlineCharacterSet];
	NSCharacterSet * quotes = [NSCharacterSet characterSetWithCharactersInString:@"\" \t\n"];
	
	NSMutableDictionary * dict = [NSMutableDictionary dictionary];
	
	while([scanner scanUpToCharactersFromSet:newline_set intoString:&line] ) {
		//i.e. scanner was able to scan some line, it is stored in line object
				
		NSArray * line_parts = [line componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"/"]];
				

		NSString * key = [[line_parts objectAtIndex:1] stringByTrimmingCharactersInSet:quotes];
		NSString * val = [[line_parts objectAtIndex:0] stringByTrimmingCharactersInSet:quotes];
		
		//NSLog(@"Key: %@, Val: %@", key, val);
		[dict setObject:val forKey:key];
		
		
		[scanner scanCharactersFromSet:newline_set intoString:0];
		
	}
	
	return dict;
}

@end
